package runesim.node;
import java.util.HashMap;
import java.io.*;
import bsh.*;
public class ScriptMap {

			static {
				packetScriptMap = new HashMap<Integer,Interpreter>();
			}
	
			static HashMap<Integer,Interpreter> packetScriptMap;
			
			public static HashMap<Integer, Interpreter> getMap(){
				return packetScriptMap;
			}
			
			public static void load() throws IOException, EvalError {
				int total = 0;
				packetScriptMap.clear();
				
				BufferedReader br = new BufferedReader(new FileReader("packetDefs.ini"));
				
				String line;
				
				while((line = br.readLine()) != null){
					if(line.startsWith("#") || line.length() == 0) continue;
					String[] tokens = line.split("=");
					Interpreter i = new Interpreter();
					i.source("scripts"+File.separator+"packets"+File.separator+tokens[1]+".resc");
					packetScriptMap.put(Integer.parseInt(tokens[0]), i);
					total++;
				}
				
				br.close();
				
				System.out.println("Loaded "+total+" packet definitions.");
			}
}
